package com.simin.base.apputils;

import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;

/**
 * Created by wsm on 2024/10/25.
 * <p>
 */
public class NotificationUtils {

    // 检查通知是否开启
    public static boolean areNotificationsEnabled(Context context) {
        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        if (mNotificationManager != null) {
            return mNotificationManager.areNotificationsEnabled();
        }
        return false;
    }

    /**
     * 打开通知权限
     *
     * @param context
     */
    public static void openNotificationSettingsForApp(Context context) {
        // Links to this app's notification settings.
        Intent intent = new Intent();
        intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
        intent.putExtra("app_package", context.getPackageName());
        intent.putExtra("app_uid", context.getApplicationInfo().uid);
        // for Android 8 and above
        intent.putExtra("android.provider.extra.APP_PACKAGE", context.getPackageName());
        context.startActivity(intent);
    }
}
